/*
 * @Description: 用户接口封装
 * @Autor: GuluGuluu
 * @Date: 2022-12-02 17:35:33
 * @LastEditors: GuluGuluu
 * @LastEditTime: 2023-07-02 15:04:08
 */
import Request from "../request";

export const TOKEN_KEY = "exam-token";

const UserService = {
  getInfo: (token) => Request.post(`/check`, { token }).then((res) => res.data),
  login: (data) => {
    return Request.post(`/login`, data).then((res) => {
      const { code, msg, data } = res;
      if (code !== 200) throw new Error(msg);
      const { token } = data;
      window.localStorage.setItem(TOKEN_KEY, token);
      return data;
    });
  },
  logout: () => {
    window.localStorage.removeItem(TOKEN_KEY);
  },
};
export default UserService;
